<template>
  <div class="order-item-con">

    <div class="order-box">
      <div class="order-top">
        <div class="logo">
          <img src="https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/e1f03f361e857881963e47ea2c7270ef.png" alt="">
          小米商城
        </div>
        <div class="status">
          {{list.status===1?'等待付款':'支付成功'}}
        </div>
      </div>
      <div class="order-list">
        <OrderList :product="list.product"></OrderList>
      </div>
      <div class="order-msg">
        <div class="time">{{list.time}}</div>
        <div class="msg" v-show="list.status===1">
          <span class="sum">共 {{sum}} 件商品</span>
          应付金额:
          <span class="price">{{price}}元</span>
        </div>
      </div>
      <!-- 取消或者付款订单 -->
      <div class="order-button" v-show="list.status===1">
        <span class="cancel" @click="cancel">取消订单</span>
        <span class="goPay" @click="goPay">立即付款</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'OrderItem',
  props: ['list'],
  computed: {
    // 总价
    price() {
      return this.list.product.reduce((sum, item) => (sum += item.num * item.price), 0)
    },
    // 总数
    sum() {
      return this.list.product.reduce((sum, item) => (sum += item.num), 0)
    }
  },
  methods: {
    cancel() {
      this.$store.commit('removeOrderListById', this.list.id)
    },
    // 付款
    goPay() {
      this.$router.push(`/pay/${this.list.id}`)
    }
  }
}
</script>

<style lang="less" scoped>
.order-item-con {
  margin-bottom: 20px;
  .order-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 17px 28px;
    font-size: 32px;
    border-bottom: 1px solid #ccc;
    .logo {
      img {
        width: 40px;
        height: 40px;
        vertical-align: middle;
      }
    }
    .status {
      color: #ff5722;
      font-size: 26px;
    }
  }
  .order-msg {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 28px;
    .time {
      color: #919191;
      font-size: 26px;
    }
    .msg {
      .sum {
        margin-right: 5px;
      }
      .price {
        color: #7f7f7f;
        font-size: 36px;
      }
    }
  }
  .order-button {
    padding: 15px 28px 20px;
    text-align: right;
    span {
      display: inline-block;
      width: 147px;
      height: 60px;
      margin-left: 20px;
      border: 1px solid #bfbfbf;
      font-size: 24px;
      text-align: center;
      line-height: 60px;
    }
    .goPay {
      border-color: #ffa05f;
    }
  }
}
</style>
